//
//  Checkpoint.m
//  server
//
//  Created by Jan Nase on 23.12.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Checkpoint.h"

@implementation Checkpoint

@synthesize position_long, position_lat, points, checkpointID, caughtBy;

-(id)initWithID: (NSString*)pID andLong: (double)x andLat: (double)y andPoints: (int)pPoints{
	self = [super init];
	if(self){
		checkpointID = [[NSString alloc] initWithString:pID];
		position_long = x;		
		position_lat = y;				
		points = pPoints;
    caughtBy = [[NSMutableArray alloc] initWithCapacity:3];
	}
	return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder{
  self = [super init];
  if (self) {
    checkpointID = [[NSString alloc] initWithString:[aDecoder decodeObjectForKey:@"checkpointID"]];
    position_long = [aDecoder decodeDoubleForKey:@"position_x"];
    position_lat = [aDecoder decodeDoubleForKey:@"position_y"];	
    points = [aDecoder decodeIntForKey:@"points"];	
    caughtBy = [[aDecoder decodeObjectForKey:@"caughtBy"] retain];	
  }
    
  return self;
}

-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:checkpointID forKey:@"checkpointID"];
    [aCoder encodeDouble:position_long forKey:@"position_x"];
    [aCoder encodeDouble:position_lat forKey:@"position_y"];
    [aCoder encodeInt:points forKey:@"points"];	
    [aCoder encodeObject:caughtBy forKey:@"caughtBy"];	
}

-(void)dealloc{
    [checkpointID release];
    [caughtBy release];
	[super dealloc];
}

#pragma Located methods

-(double) latitude {
  return position_lat;
}

-(double) longitude {
  return position_long;
}

-(double) accuracy {
  return 0;
}

-(NSDate*) lastUpdate {
  return nil;
}

@end
